/* Original Author:  Dominick O'Dierno
 * Date: 2007   odiernod@gmail.com     --Originally intended for use with DOMercury:  http://www.odierno.com/domercury
 * Description: Provides actions for an Text Item
 * 
 * --CHANGELOG--
 * 
 * */
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using DOMercury.Interfaces;
using DOMercury.Items;


namespace DOMercury.Actions
{
    class TextExecuteCommandAction : Interfaces.IAction
    {
        #region IAction Members

        public string ActionType
        {
            get
            {
                return "Execute Command";
            }
        }

        public string Description
        {
            get
            {
                return "Executes the command";
            }
        }

         public string ParamDescription
        {
            get
            {
                return "Command Line Parameters for the Command";
            }
        }

        public string ParameterType
        {
            get
            {
                return "CommandLine";
            }
        }

        public bool Perform(IItem item, object specialParams)
        {
            try
            {
                string[] args = ((TextItem)(item)).Text.Split(' ');
                string param = ((TextItem)(item)).Text.Remove(0, args[0].Length) + " " + ((string)(specialParams));
                Process.Start(args[0], param.Trim());
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion
    }

    class TextExecuteCommandInShellAction : Interfaces.IAction
    {
        #region IAction Members

        public string ActionType
        {
            get
            {
                return "Execute Command in Shell";
            }
        }

        public string Description
        {
            get
            {
                return "Executes the command in a command line shell";
            }
        }

        public string ParamDescription
        {
            get
            {
                return "Command Line Parameters for the Command";
            }
        }

        public string ParameterType
        {
            get
            {
                return "CommandLine";
            }
        }

        public bool Perform(IItem item, object specialParams)
        {
            try
            {
                Process.Start("cmd", "/k " + ((TextItem)item).Text + " " + (string)specialParams);
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion
    }

    class TextOpenInIEAction : Interfaces.IAction
    {
        #region IAction Members

        public string ActionType
        {
            get
            {
                return "Open in Internet Explorer";
            }
        }

        public string Description
        {
            get
            {
                return "Open the item in Internet Explorer";
            }
        }

        public string ParamDescription
        {
            get
            {
                return "Unused";
            }
        }

        public string ParameterType
        {
            get
            {
                return "CommandLine";
            }
        }

        public bool Perform(IItem item, object specialParams)
        {
            try
            {
                Process.Start("iexplore.exe", ((TextItem)item).Text);
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion
    }

}
